#include "ChatGrpcClient.h"
#include "configMgr.h"
ChatGrpcClient& ChatGrpcClient::GetInst()
{
	static ChatGrpcClient instance;
	return instance;
}

message::AddFriendRsp ChatGrpcClient::NotifyAddFriend(std::string server_ip, const message::AddFriendReq& req)
{
	return message::AddFriendRsp();
}

message::AuthFriendRsp ChatGrpcClient::NotifyAuthFriend(std::string server_ip, const message::AuthFriendReq& req)
{
	return message::AuthFriendRsp();
}

bool ChatGrpcClient::GetBaseInfo(std::string base_key, int uid, std::shared_ptr<UserInfo>& userinfo)
{
	return false;
}

message::TextChatMsgRsp ChatGrpcClient::NotifyTextChatMsg(std::string server_ip, const message::TextChatMsgReq& req, const Json::Value& rtvalue)
{
	return message::TextChatMsgRsp();
}

ChatGrpcClient::ChatGrpcClient() {
	auto& cfg = configMgr::GetInst();
	auto server_list = cfg["PeerServer"]["Servers"];

	std::vector<std::string> words;

	std::stringstream ss(server_list);
	std::string word;

	while (std::getline(ss, word, ',')) {
		words.push_back(word);
	}

	for (auto& word : words) {
		if (cfg[word]["Name"].empty()) {
			continue;
		}
		_pool[cfg[word]["Name"]] = std::make_unique<ChatConPool>(5, cfg[word]["Host"], cfg[word]["Port"]);
	}
}
